package edu.vt.ece.rt.quorum.messsages.types;

import java.util.Set;

import org.jgroups.Address;

import edu.vt.ece.rt.dstm.Context;
import edu.vt.ece.rt.quorum.messsages.MessageHandler;
import edu.vt.ece.rt.quorum.messsages.QMessage;
import edu.vt.ece.rt.quorum.util.ReplyListStore;
import edu.vt.ece.rt.util.Logger.Logger;

/*
 * Commit Response Message to commit DSTM transaction request
 * @author Sudhanshu
 */
public class CommitResponse extends QMessage implements Runnable {
	Set<Context> list;			//Specify the Aborted Transaction List
	Long txnId; 		//Specify the transaction number, Can be Converted to Context Class, if some MetaData required
	boolean commit;		//Commit true or abort

	public CommitResponse(Set<Context> l, Long tid, boolean c) {
		super(MessageType.CommitResponse);
		list = l;
		txnId = tid;
		commit = c;
	}
	
	@Override
	public void run() {
		Logger.debug("Commit response " + commit +" for txnId "+txnId+" from "+getSrcAddr());
		ReplyListStore rls = MessageHandler.commitRequestQueue.get(txnId);
		if(rls !=null){
			rls.processMessage(txnId, list, commit);
		}
		//if null means given transaction is already aborted nothing else to do
	}	
}
